

import bpy

from 节点.全局控制.Node.节点和插座基类 import bl_节点基类
from 节点.Core import bl_UI配色
from 节点.Core import bl_Mesh

import engine.initLIB.load_dll as engineLib
import ctypes

engineLib.flexCAPI.f_创建导出网格缓存节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建导入网格缓存节点.restype = ctypes.c_bool







E_网格缓存类型枚举 = [
	("TYPE_PC2", "*.pc2", "", 0),
	("TYPE_VERT", ".vert", "", 1),
]


def f_update_网格缓存类型枚举(self, context):
	data = [list('TYPE_缓存类型'), list(str(self.m_网格缓存类型))]
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])

def f_update_网格缓存路径枚举(self, context):
	data = [list('TYPE_缓存路径'), list(str(bpy.path.abspath(self.m_网格缓存路径)) )]
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])

def f_update_网格缓存名称枚举(self, context):
	data = [list('TYPE_缓存名称'), list(str(self.m_网格缓存名称))]
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])

class C_Node_导出网格缓存(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_网格导出缓存'
	bl_label = '网格导出缓存'
	
	m_网格缓存类型 = bpy.props.EnumProperty(items=E_网格缓存类型枚举, name="缓存类型", default="TYPE_VERT", update=f_update_网格缓存类型枚举)
	m_网格缓存路径 = bpy.props.StringProperty(name="路径", subtype='DIR_PATH', update=f_update_网格缓存路径枚举)
	m_网格缓存名称 = bpy.props.StringProperty(name="名称", default='导出网格', update=f_update_网格缓存名称枚举)
	def init(self, context):
		super(C_Node_导出网格缓存, self).f_init(context)
		self.inputs.new('C_Socket_网格_Array1D', name='网格')
		self.inputs.new('C_Socket_I32', name='帧')
		self.f_toCPP();

	def draw_buttons(self, context, layout):
		layout.prop(self, 'm_网格缓存类型')
		layout.prop(self, 'm_网格缓存路径')
		layout.prop(self, 'm_网格缓存名称')
		
	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建导出网格缓存节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			f_update_网格缓存类型枚举(self, None)
			f_update_网格缓存路径枚举(self, None)
			f_update_网格缓存名称枚举(self, None)
			self.use_custom_color = True
			self.color = bl_UI配色.g_网格类节点颜色


class C_NODE_MENU_导出网格缓存(bpy.types.Operator):
	bl_idname = 'node.global_node_obj_meshs_export_buffer'
	bl_label = '导出网格缓存'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_导出网格缓存', use_transform=True)
		return {'FINISHED'}






#D:\Class_3D\blender-2.81\blender.exe -b I:\Item\19_10_16_广州速冻\场景/场景镜头跟踪_v1_n1.blend -s 250 -e 300 -a




class C_Node_导入网格缓存(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_网格导出缓存'
	bl_label = '网格导出缓存'
	
	m_网格缓存类型 = bpy.props.EnumProperty(items=E_网格缓存类型枚举, name="缓存类型", default="TYPE_VERT", update=f_update_网格缓存类型枚举)
	m_网格缓存路径 = bpy.props.StringProperty(name="路径", subtype='FILE_PATH', update=f_update_网格缓存路径枚举)
	#m_网格缓存名称 = bpy.props.StringProperty(name="名称", update=f_update_网格缓存名称枚举)
	def init(self, context):
		super(C_Node_导入网格缓存, self).f_init(context)
		#self.inputs.new('C_Socket_网格_Array1D', name='网格')
		self.inputs.new('C_Socket_I32', name='帧')
		self.inputs.new('C_Socket_I32', name='偏移')
		self.outputs.new('C_Socket_Vec3_Array1D', name='顶点')
		self.f_toCPP(self.id_data);

	def draw_buttons(self, context, layout):
		layout.prop(self, 'm_网格缓存类型')
		layout.prop(self, 'm_网格缓存路径')
		#layout.prop(self, 'm_网格缓存名称')
		
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建导入网格缓存节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			f_update_网格缓存类型枚举(self, None)
			f_update_网格缓存路径枚举(self, None)
			#f_update_网格缓存名称枚举(self, None)
			self.use_custom_color = True
			self.color = bl_UI配色.g_网格类节点颜色


class C_NODE_MENU_导入网格缓存(bpy.types.Operator):
	bl_idname = 'node.global_node_obj_meshs_impurt_buffer'
	bl_label = '导入网格缓存'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_导入网格缓存', use_transform=True)
		return {'FINISHED'}












classes = (
	C_Node_导出网格缓存,
	C_NODE_MENU_导出网格缓存,

	C_Node_导入网格缓存,
	C_NODE_MENU_导入网格缓存,


)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)






